﻿using System;
using Microsoft.Xna.Framework;
//using OrganizedConfusion;

namespace OrganizedConfusion.Game_Objects
{
    public class Player : BaseObject
    {
        Vector2 velocity;
        bool FacingLeft;
        public float Rotation;
        public CheckpointFlag MyCheckpoint;
        public Vector2 StartPos;
        private GamePlay TheGame;

        public Player()
        {
            velocity = new Vector2(0, 0);
            //Position = new Vector2(340, 350);
            FacingLeft = false;
            base.type = OBJ_TYPE.OBJ_PLAYER;
            MyCheckpoint = null;
        }

        public bool GetFacing() { return FacingLeft; }

        public void SetGame(GamePlay game) { TheGame = game; }

        public void Update(GameTime gametime)
        {
            Velocity = new Vector2(Velocity.X, Velocity.Y + 9.81f);

            Vector2 tempPos = Position;
            tempPos.X = Position.X + (Velocity.X * (gametime.ElapsedGameTime.Milliseconds / 1000.0f));
            tempPos.Y = Position.Y + (Velocity.Y * (gametime.ElapsedGameTime.Milliseconds / 1000.0f));

            if (Velocity.X < 0.0f)
                FacingLeft = true;
            else
                FacingLeft = false;

            Position = tempPos;

            if (!FacingLeft)
                Rotation += (float)(gametime.ElapsedGameTime.Milliseconds / 1000.0f);
            else
                Rotation -= (float)(gametime.ElapsedGameTime.Milliseconds / 1000.0f);
            
        }

        public Vector2 Velocity
        {
            get { return velocity; }
            set { velocity = value; }
        }

        public void Reset() { TheGame.Reset(); }
    }
}
